﻿
using RTW.DAL;
using RTW.OA.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RTW.OA.Areas.Common.Servers
{
    public class EvectionServers
    {
	    private readonly IRepository<attend_evection> attend_evectionRepository;

        public EvectionServers()
        {
            attend_evectionRepository = new DapperRepository<attend_evection>();

        }

        public List<attend_evection> GetData()
        {
            var datas = attend_evectionRepository.GetAllEnumerable();

					  			return datas.ToList();
        }

        public attend_evection GetModelById(string id)
        {
            return attend_evectionRepository.GetById(id);
        }

		
        internal void Add(attend_evection model)
        {
            attend_evectionRepository.Insert(model);
        }

        internal void Update(attend_evection model)
        {
            attend_evectionRepository.Update(model);
        }

		internal void Del(string id)
        {
            attend_evectionRepository.DeleteByIds(id);
        }

				      
        internal List<SelectListItem> GetSTATUS()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = attend_evectionRepository.SqlWithParamsDynamic("select a.name Value,concat(a.name,'-----',convert(nvarchar(max),b.value)) Text from sys.tables  a inner join  sys.extended_properties b on a.object_id=b.major_id and b.minor_id=0");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }


                   
        internal List<SelectListItem> GetLEADER_ID()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            //var dstable = attend_evectionRepository.SqlWithParamsDynamic("select a.name Value,concat(a.name,'-----',convert(nvarchar(max),b.value)) Text from sys.tables  a inner join  sys.extended_properties b on a.object_id=b.major_id and b.minor_id=0");
            var dstable = attend_evectionRepository.SqlWithParamsDynamic("SELECT [USER_NAME] AS 'Text',[USER_ID] AS 'Value' FROM [OADB].[dbo].[users] WHERE [STATUS]=0");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }


                   
        internal List<SelectListItem> GetALLOW()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = attend_evectionRepository.SqlWithParamsDynamic("select a.name Value,concat(a.name,'-----',convert(nvarchar(max),b.value)) Text from sys.tables  a inner join  sys.extended_properties b on a.object_id=b.major_id and b.minor_id=0");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }


                   	}
}